package br.com.gestaofacil.dao.autenticacao.impl;

import java.util.List;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;
import org.springframework.stereotype.Component;

import br.com.gestaofacil.autenticacao.core.model.User;
import br.com.gestaofacil.dao.autenticacao.IAutenticacaoDAO;

@Component
public class AutenticacaoDAOImpl implements IAutenticacaoDAO{

	SessionFactory sf = new AnnotationConfiguration().configure().buildSessionFactory();
	Session session = sf.openSession();
	
	public List<User> findUsers() {
		@SuppressWarnings("unchecked")
		List<User> usuario = (List<User>) session.createQuery("from " + User.class.getName()).list();
		return usuario;
	}
	
	public User findUserByUserName(String username) {
		List<User> usuario = (List<User>) session.createQuery("from " + User.class.getName()).list();
		return usuario.get(0);
	}

}
